﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTT.Core.Library;
using System.Web.Security;

public partial class Admin_ListMembers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        LoadData();
    }

    private void LoadData()
    {
        var users = Membership.GetAllUsers();

        var userList = new List<MembershipUser>();
        foreach (MembershipUser user in users)
        {
            userList.Add(user);
        }
        repMain.DataSource = userList;
        repMain.DataBind();

    }

    public string getIconActive(bool IsActive)
    {

        string st = "";
        if (IsActive)
            st = "icon-thumbs-up";
        else
            st = "icon-thumbs-down";
        return st;
    }
    public string getButtonActive(bool IsActive)
    {

        string st = "";
        if (IsActive)
            st = "btn btn-info";
        else
            st = "btn btn-inverse";
        return st;
    }

    protected void repMain_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

        //DataService services = new DataService();
        string username = e.CommandArgument.ToString();
        //MembershipUser user = Membership.GetUser(username);
        //UsersEntity userAU = UsersManager.CreateInstant().SelectByUserNameLST(username)[0];
        switch (e.CommandName)
        {
            case "reset":
                #region reset
                if (!string.IsNullOrEmpty(username) && (!string.IsNullOrEmpty(Util.CurrentUserName)) &&
                            Util.CurrentUserName != username)
                {
                    //call method reset password for User by Dataservice
                    bool rt = false, rtt = false;
                    //Membership.
                    if (rt)
                    {
                        //CookieManager.setCookie(Page, "msg", "info|Thông báo|Làm mới mật khẩu thành công cho tài khoản: <strong>" + username + "</strong>, mật khẩu mới là: " + ConfigurationManager.AppSettings["PasswordDefault"]);
                    }
                    else
                    {

                    }
                }
                else
                {

                }
                break;
                #endregion

            case "edit":
                //Response.Redirect("~" + PublicContants.RootPath + "Default.aspx?mod=profilemember&u=" + username);
                break;
            case "delete":
                #region delete
                if (!string.IsNullOrEmpty(username) && (!string.IsNullOrEmpty(Util.CurrentUserName)) &&
                    Util.CurrentUserName != username)
                {

                    try
                    {
                        Membership.DeleteUser(username);
                    }
                    catch { }
                    lblmsg.Text = "Đã xóa thành công tài khoản: <strong>" + username + "<strong>!";

                }
                else
                {
                    lblmsg.Text = "Không thể xóa tài khoản đang sử dụng!";


                }
                break;
                #endregion
        }
        //Response.Redirect(Request.RawUrl);
    }
}